﻿using Newtonsoft.Json;

namespace iOSClub.WebAPI.Services;

//HTTP请求
static class HttpClientService<T>
{
    static HttpClient m_Client;

    static HttpClientService()
    {
        m_Client = new HttpClient();
    }

    public static async Task<T> GetAsync(string url)
    {
        var res = await m_Client.GetAsync(url);

        res.EnsureSuccessStatusCode();

        var resContent = await res.Content.ReadAsStringAsync();

        if (!string.IsNullOrEmpty(resContent))
        {
            return JsonConvert.DeserializeObject<T>(resContent);
        }
        else
        {
            throw new Exception("HTTP Get Error");
        }
    }
}
